
import {format} from 'silly-datetime'

export function timeFormat(time: number | string | Date) {
    let now = Date.now()
    const diff = now - new Date(time).getTime()

    if (diff / (1000 * 3600 * 24 * 365) >= 1) {
        return format(time, `YYYY-MM-DD HH:mm`)
    } else {
        return format(time, `MM-DD HH:mm`)
    }
}
import * as cheerio from 'cheerio'
export function lowerPostImage(post:any) {
    const $_ = cheerio.load(post.content, null, false)
    // console.log($_.html())
    let img = $_('img').remove()
    img.removeAttr('class')
    // $_._root.children.push(...img)
    post.images = []
    for (let i of img) {
        post.images.push(i.attribs['src'])
        i.attribs['width'] = '100'
        // i.attribs['height'] = '100'
    }
    post.content = $_.html()
}
